package com.gpzx.zx.module.mine.frame.view

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.gpzx.zx.R
import com.gpzx.zx.module.home.ui.activity.InfoWebViewActivity
import com.gpzx.zx.module.mine.ui.CollectionAdapter
import com.gpzx.zx.module.mine.ui.activity.CollectionActivity
import com.qmuiteam.qmui.widget.QMUITopBar
import com.wkq.base.frame.mosby.delegate.MvpView
import com.wkq.database.dao.CollectionNewsInfo
import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wu.common.utils.StatusBarUtil

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/7/17
 *
 * 用途:
 */


class CollectionView : MvpView {

    var mAdapter: CollectionAdapter? = null
    var mActivity: CollectionActivity

    constructor(activity: CollectionActivity) {
        mActivity = activity
    }

    fun initView() {
        initToolBar("我的收藏")
        mActivity.binding.rvContent.layoutManager = LinearLayoutManager(mActivity)
        mAdapter = CollectionAdapter(mActivity, R.layout.item_collection)
        mActivity.binding.rvContent.adapter = mAdapter
        mAdapter!!.setOnViewClickListener(object : KtDataBindingAdapter.OnAdapterViewClickListener<CollectionNewsInfo> {
            override fun onViewClick(v: View?, program: CollectionNewsInfo?) {
                InfoWebViewActivity().newInstance(mActivity as Context, program?.type, program?.id, program?.news_title)
            }
        })


    }

    private fun initToolBar(title: String?) {
        StatusBarUtil.setStatusBarDarkMode(mActivity)
        StatusBarUtil.setColor(mActivity, mActivity!!.getResources().getColor(R.color.color_2b2b2b), 0)
        var toolbar = mActivity!!.binding.includeToolbar as QMUITopBar
        toolbar.setTitle(title)
        toolbar.setBackgroundColor(mActivity!!.resources.getColor(R.color.color_2b2b2b))
        toolbar.addLeftImageButton(R.drawable.ic_arrow_back_white_24dp, R.id.qmui_topbar_item_left_back).setOnClickListener { mActivity!!.finish() }

    }

    fun showData(collectionList: List<CollectionNewsInfo>) {
        if (collectionList.size == 0) {
            mActivity.binding.rvContent.visibility = View.GONE
            mActivity.binding.empty.visibility = View.VISIBLE
        } else {
            mAdapter!!.addItems(collectionList.toMutableList())
        }

    }
}